class_name ruleSystem extends Node

static func validate_gem_take(player: PlayerState, gems_taken: Array):
	# 验证拿取宝石是否符合规则（最多3不同色/同色2个等）
	var total = 0
	var sameColor_2 = false
	for item in gems_taken:
		total += item
		if item >= 2:
			sameColor_2 = true
	if total > 3:
		return false
	elif total == 3 && sameColor_2 :
		return false
	elif total == 2 && sameColor_2 :
		for idx in gems_taken.size():
			if gems_taken[idx] == 2 && GameManager.available_gems[idx] != 2:
				return false
	if total + player.totalGems() > 10:
		return false
	return true

static func can_purchase_card(player: PlayerState, card: CardData):
	# 检查玩家是否能购买该卡牌（包括永久加成计算）
	var cost = card.cost.duplicate()
	for item in player.bonuses:
		var obj = player.bonuses
		if cost[item] > 0 && obj[item] > 0:
			cost[item] = 0 if cost[item] - obj[item] < 0 else cost[item] - obj[item]
	var chajia = 0 #缺少的筹码
	var can_buy = true
	for item in cost:
		if cost[item] > player.gems[item]:
			chajia += cost[item] - player.gems[item]
	if chajia > player.gems[5]:
		return false
	return true
